<template>
<view class="addressadd">
	
	<block v-if="zhiya_status == 1">
		<form id="setform" @submit="confirmExit">
			<view class="form">
				<view style="text-align: center;padding-top: 25rpx;font-size: 20px;margin-bottom: 20rpx;">
					已入驻信息
				</view>
				<view class="form-item">
					<label class="label">商家級別</label>
					<view class="f2 flex flex1">{{info.business_level}}</view>
				</view>
				<view class="form-item">
					<label class="label">支付金额</label>
					<view class="f2 flex flex1">
						{{info.zhiya_price}}
					</view>
				</view>
				
				<view class="form-item">
					<label class="label">服务费率</label>
					<view class="f2 flex flex1"> {{info.business_service_fee}} %</view>
				</view>
				<view class="form-item">
					<label class="label">让利范围</label>
					<view class="f2 flex flex1"> {{info.business_rangli}}</view>
				</view>
				<view class="form-item">
					<label class="label">入驻时间</label>
					<view class="f2 flex flex1"> {{info.zhiya_time}}</view>
				</view>
				<view class="form-item">
					<label class="label">到期时间</label>
					<view class="f2 flex flex1"> {{info.expire_time}}</view>
				</view>
			</view>
			<!-- <button class="savebtn" style="background:linear-gradient(45deg,#FD4D49 0%,#FB6966 80%)" form-type="submit">退出质押</button> -->
		</form>
		<!-- <view style="background-color: #fff;width: 95%;margin:25rpx auto;border-radius: 5rpx;padding: 10rpx;">
			<view class="sm-title">退出质押说明</view>
			<view class="sm-1">1.所有订单已关闭或已完成</view>
			<view class="sm-1">2.所有商品已下架</view>
		</view> -->
	</block>
	<block v-if="zhiya_status == 2 || info.zhiya_is_upgrade == 1">
	<form id="setform" @submit="confirm">
		<view class="form">
			
			<view class="zhiya_list">
				<view class="title">商家级别</view>
				<view class="content">
					<radio-group class="radio-group" name='business_zhiya' @change="changeZhiYa">
						<label v-for="(item1,idx1) in zhiya_list" :key="item1.id" >
							<radio class="radio" :disabled="my_level == item1.id" :value="item1.id"/>{{item1.title}}
						</label>
					</radio-group>
				</view>
			</view>
			
		</view>
		<button class="savebtn" style="background:linear-gradient(45deg,#FD4D49 0%,#FB6966 80%)" form-type="submit">{{my_level == ''?'确定开通年费':'确定升级'}}</button>
	</form>
	</block>
</view>
</template>

<script>
var app = getApp();

export default {
  data() {
    return {
			opt:{},
			loading:false,
			isload: false,
			info:[],
			zhiya_status: 2,
			zhiya_id:0,
			zhiya_list:[],
			my_level:''
    };
  },
  onLoad: function (opt) {
		this.opt = app.getopts(opt);
		this.getdata();
  },
  methods: {
		getdata:function(){
			var that = this;
			that.loading = true;
			app.get('ApiAdminIndex/getBusinessZhiYa', {}, function (res) {
				console.log(res)
				res.list.map(e=>{
					if(res.data.business_level == e.title){
						that.my_level = e.id;
						return e;
					}
				})
				if(res['status'] == 1){
					that.zhiya_status = 1;
					that.info = res.data;
					that.zhiya_list = res.list;
					that.loaded();
				}else if(res['status'] == 2){
					that.zhiya_status = 2;
					that.info = res.data;
					that.zhiya_list = res.list;
					that.loaded();
				}else{
					pp.error(res.data);
				}
				//
			});
		},
	changeZhiYa:function(e){
		var that = this;
		that.zhiya_id = e.detail.value;
	},
    confirm: function (e) {
      var that = this;
    
	  var zy_id = that.zhiya_id
      

      if(zy_id == 0){
        app.error('请选择商家级别');
        return false;
      }
	  if(this.my_level == ''){
		  var title = '开通';
	  }else{
		  var title = '升级';
	  }
      app.confirm('确定要'+title+'商家会员吗?', function () {
		  
		  app.showLoading(title+'中');
		  app.post('ApiAdminIndex/businessZhiYa',{zy_id:zy_id},function(res){
		  				app.showLoading(false);
		    if (res.status == 1) {
		      app.success(res.msg);
		      app.goto('/pages/pay/pay?id='+res.payorderid);
		    } else {
		      app.error(res.msg);
		    }
		  });
	  });
	  
    },
	confirmExit: function (e) {
	  var that = this;
	  var formdata = e.detail.value;
	  var pwd_pwd = formdata.pwd_pwd;
	
	  
	  if(!pwd_pwd){
	    app.error('请输入支付密码');
	    return;
	  }
	  uni.showModal({
	      title: '退出质押',
	      content: '确定要退出质押吗？',
	      success: function (res) {
	          if (res.confirm) {
				  app.showLoading('退出中');
				  app.post('ApiAdminIndex/businessQuitZhiYa',{pwd_pwd: pwd_pwd},function(res){
				  	app.showLoading(false);
				    if (res.status == 1) {
				      app.success(res.msg);
				      setTimeout(function () {
				        app.goto('index');
				      }, 1000);
				    } else {
				      app.error(res.msg);
				    }
				  });
	          } else if (res.cancel) {
	              console.log('用户点击取消');
	          }
	      }
	  });

			
	}
  }
};
</script>
<style>
.sm-title{height: 60rpx;line-height: 60rpx;color: #8B8B8B;}
.sm-1{height: 50rpx;line-height: 50rpx;color: #8B8B8B;}
.form{ width:94%;margin:20rpx 3%;border-radius:5px;padding: 0 3%;background: #FFF;}
.form-item{display:flex;align-items:center;width:100%;border-bottom: 1px #ededed solid;height:98rpx;line-height:98rpx;}
.form-item:last-child{border:0}
.form-item .label{ color:#8B8B8B;font-weight:bold;height: 60rpx; line-height: 60rpx; text-align:left;width:200rpx;padding-right:20rpx}
.form-item .input{ flex:1;height: 60rpx; line-height: 60rpx;text-align:right}

.zhiya_list{
	display: flex;
	flex-direction: column;
	width: 90%;
	margin: auto;
}
.zhiya_list .title {
	height: 80rpx;
	line-height: 80rpx;
	font-size: 18px;
}
.zhiya_list .content{
	
}
.zhiya_list .content .radio-group{
	display: flex;
	flex-direction: column;
	height: 250rpx;
}
.zhiya_list .content .radio-group label{
	height: 70rpx;
	line-height: 70rpx;
}

.savebtn{ width: 90%; height:96rpx; line-height: 96rpx; text-align:center;border-radius:48rpx; color: #fff;font-weight:bold;margin: 0 5%; margin-top:60rpx; border: none; }




</style>